/**
* @author maze | guavestudios.com
* @license MIT License see LICENSE.TXT
* @version 0.1
*/
package com.guavestudios.fcon {
	import com.guavestudios.fcon.util.KeyMatcher;
	import flash.display.*;
	import com.guavestudios.fcon.core.*;
	import com.guavestudios.fcon.api.*;
	import com.guavestudios.fcon.plugins.*;
	import com.guavestudios.fcon.commands.*;
	import com.guavestudios.fcon.format.IAppender;
	import flash.utils.Dictionary;

	public class AbstractConsole extends Sprite implements IControlableConsole{
		
		//{ STATIC
	
		//NO STATIC DEFINITIONS
		//CANT BE DEFINED IN INTERFACE
		//}
		
		//{ MEMBERS
		protected var config:XML;
		
		protected var appender:IAppender;
		
		protected var pluginManager:PluginManager;
		protected var commands:CommandManager;
		protected var pathParser:IPathParser;
		
		protected var consoleLook:IConsoleLook;
		//}
		
		//{ GETTER-SETTER
		/**
		* TODO Insert description from GET config here.
		*  
		*  @return XML
		*/
		public function getConfig(idString:String):XML {
			if (config)
			{
				try {
					return config.setting.(@id==idString)[0];
				} catch (err:Error) {
					return null;
				}
			}
			return null;
		}
		public function hasConfig(id:String):Boolean
		{
			if (config.setting.(@id == id).length() > 0)
				return true;
			else 
				return false;
		}
		/**
		* TODO Insert description from GET appender here.
		*  
		*  @return IAppender
		*/
		public function getAppender():IAppender {
			return this.appender;
		}
		/**
		* TODO Insert description from SET appender here.
		*  
		*  @param pappender[IAppender]
		*  @return
		*/
		public function setAppender(pappender:IAppender):void {
			this.appender = pappender;
		}
		/**
		* TODO Insert description from GET pathParser here.
		*  
		*  @return IPathParser
		*/
		public function getPathParser():IPathParser {
			return this.pathParser;
		}
		/**
		* TODO Insert description from GET consoleLook here.
		*  
		*  @return ConsoleLook
		*/
		public function getConsoleLook():IConsoleLook {
			return this.consoleLook;
		}
		/**
		* TODO Insert description from SET consoleLook here.
		*  
		*  @param pconsoleLook[ConsoleLook]
		*  @return
		*/
		public function setConsoleLook(pconsoleLook:IConsoleLook):void {
			this.consoleLook = pconsoleLook;
		}
		//}
		public function AbstractConsole() {
			
			
			init();	
		}
		private function init():void {
			
		}
		//{ PUBLIC FUNCTIONS
		public function trace(s:String):void
		{
			outputText(s);
		}
		public function execute(s:*):void
		{
			
		}
		public function outputText(s:String):void
		{
			appender.append(s);
		}
		public function getOpenKey():KeyMatcher
		{
			return null;
		}
		//PLUGIN MANAGER
		public function getPlugin(s:String):IConsolePlugin
		{
			return pluginManager.getPlugin(s);
		}
		public function hasPlugin(s:String):Boolean
		{
			return pluginManager.hasPlugin(s);
		}
		public function addPlugin(p:IConsolePlugin):void
		{
			pluginManager.addPlugin(p);
		}
		public function getStage():Stage
		{
			return null;
		}
		
		//COMMAND MANAGER
		public function addCommand(com:INamedCommand):void
		{
			commands.addCommand(com);
		}
		public function addAlias(al:String,cmd:INamedCommand):void
		{
			commands.addAlias(al,cmd);
		}
		public function hasCommand(s:String):Boolean
		{
			return commands.getCommand(s)!=null;
		}
		public function getCommands():Dictionary
		{
			return commands.getCommands();
		}
		//}
		
		//{ OVERRIDEN METHODS
		
		//}
		
		//{ PRIVATE FUNCTIONS
		protected function redraw():void 
		{	
			consoleLook.update();
		}
		//}

	}
	
}
